<template>
  <div>
    <van-radio-group v-model="checked">
      <van-radio
        v-for="(item, index) in user.list"
        :key="index"
        :name="item.id"
        >{{ item.name }}</van-radio
      >
    </van-radio-group>
    <button @click="change_user">确定</button>
  </div>
</template>

<script>
import { reactive, ref, onMounted, toRefs, provide } from "vue";
import { useRoute, useRouter } from "vue-router";
import apis from "../utils/api_nots";
export default {
  setup() {
    const checked = ref("1");
    const user = reactive({
      list: [],
    });
    onMounted(() => {
      apis
        .get_user({
          page: 1,
          size: 30,
          worker_id: 17,
        })
        .then((res) => {
          user.list = res.data.data.data;
        });
    });
    const router = useRouter();
    const change_user = () => {
      const user_infor = user.list.filter((item) => {
        return item.id == checked.value;
      });
      console.log(user_infor)
      localStorage.setItem(
        "customer_user",
        JSON.stringify({
          id_number: user_infor[0].id_number,
          name: user_infor[0].name,
          contact_manner: user_infor[0].contact_manner,
          bank_name:user_infor[0].bank_name,
          bank_num:user_infor[0].bank_num,
          bank_sum_name:user_infor[0].bank_sum_name
        })
      );
      router.push({
        path: "/personal_sign"
      });
    };
    return {
      user,
      checked,
      change_user,
    };
  },
};
</script>

<style></style>
